package com.echat.messagesender.sender.util;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by chenmohan on 2018/09/10
 *
 * @description
 */
public class TemplateUtil {

    public static String translate(String content, Map<String, String> param) {
        if (param != null && param.size() > 0){
            for (Map.Entry<String, String> e : param.entrySet()) {
                content = content.replace(new String(e.getKey()), e.getValue());
            }
        }
        return content;
    }


    /**
     * unicode转换成字符串(不对外使用)
     *
     * @param str
     * @return
     */
    private static String unicodeToString(String str) {
        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
        Matcher matcher = pattern.matcher(str);
        char ch;
        while (matcher.find()) {
            ch = (char) Integer.parseInt(matcher.group(2), 16);
            str = str.replace(matcher.group(1), ch + "");
        }
        return str;
    }

}
